//
//  UserHeaderView.m
//  FbeeAPP
//
//  Created by dev-m on 2018/3/5.
//  Copyright © 2018年 mohao. All rights reserved.
//

#import "UserHeaderView.h"
#import "BeePhotoImageView.h"

@interface UserHeaderView()
{
    BeePhotoImageView *photo;
    UILabel *nickName;
    UILabel *info;
    
}

@end

@implementation UserHeaderView

-(instancetype)initWithFrame:(CGRect)frame
{
    self  = [super initWithFrame:frame];
    
    if (self) {
        
        [self buildView];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id sender) {
            if ([UserInfoManager sharedManager].isLogin) {
                [[JumpManager sharedManager] jumpToMyNickName];
            }
            else
            {
                [[JumpManager sharedManager] jumpToLogin];
            }
        }];
        [self addGestureRecognizer:tap];
        
    }
    
    return self;
}

-(void)buildView
{
    photo = [[BeePhotoImageView alloc] initWithFrame:CGRectMake(17, 0, 60, 60) photoStyle:BeePhotoDefaultStyle];
    photo.image = [UIImage imageNamed:@"user_photo_bg"];
    photo.centerY = NavBarHeight + 100/2;
    [self addSubview:photo];
    
    NSString *nicknameStr = NSLocalizedString(@"textUnLoginState", nil);
    nickName = [UILabel makeLabel:^(TTLabelExtend *make) {
        make.setFrame(CGRectZero);
        make.addText(nicknameStr);
        make.addFont([UIFont boldSystemFontOfSize:34.0f]).addTextColor(FBEE_COLOR_LARGETITLE);
        make.top = photo.top - 5;
        make.left = photo.right + 15.5;
        make.width = IPHONEWIDTH - make.left - 20;
        make.height = 48;
        [self addSubview:make];
    }];
    
    info = [UILabel makeLabel:^(TTLabelExtend *make) {
        make.setFrame(CGRectMake(0, 0, 180, 15));
        make.addText(NSLocalizedString(@"textUnLoginStateInfo", nil));
        make.addFont([UIFont systemFontOfSize:14.0f]).addTextColor(FBEE_COLOR_INFO);
        make.top = nickName.bottom + 1;
        make.left = nickName.left;
        [self addSubview:make];
    }];
}

-(void)refreshHeader
{
    if ([UserInfoManager sharedManager].isLogin) {
        
        [photo setTitle:[UserInfoManager sharedManager].nickName];
        nickName.text = [UserInfoManager sharedManager].nickName;
        info.text = [NSString stringWithFormat:@"(+%@)%@",[UserInfoManager sharedManager].areaCode,[UserInfoManager sharedManager].mobile];
        return;
    }
    
    photo.image = [UIImage imageNamed:@"user_photo_bg"];
    photo.backgroundColor = FBEE_COLOR_PLACEHOLDER;
    [photo removeAllSubviews];
    
    nickName.text = NSLocalizedString(@"textUnLoginState", nil);
    info.text = NSLocalizedString(@"textUnLoginStateInfo", nil);
}


@end
